package tgc.edu.yzy.controller;


import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import tgc.edu.yzy.entity.Grade;
import tgc.edu.yzy.entity.Student;
import tgc.edu.yzy.service.GradeService;
import tgc.edu.yzy.service.StudentService;

@Controller
@RequestMapping(value="/student")
public class StudentController {
	@Autowired
	private StudentService studentservice;
	@Autowired
	private GradeService gradeservice;
	/***
	 * 显示个人情况
	 * @param map
	 * @param session
	 * @return
	 */
	@RequestMapping(value="userinfo")
	public String userinfo(ModelMap map,HttpSession session) {
		Student attribute = (Student) session.getAttribute("students");
		List<Student> src=studentservice.findByGradeId(attribute.getId());
		map.put("grades", src);
		return "student/userinfo";
	}
	/***
	 * 显示个人成绩
	 * @param map
	 * @param session
	 * @return
	 */
	@RequestMapping(value="grading")
	public String grading(ModelMap map,HttpSession session) {
		Student attribute = (Student) session.getAttribute("students");
		System.out.println("学生显示个人成绩");
		List<Grade> grades=gradeservice.findByStudentId(attribute.getId());
		/*List<Student> grades=studentservice.findByGradeId(attribute.getId());*/
		map.put("grades", grades);
		return "student/grading";
	}
	/***
	 * 修改密码
	 * @param password
	 * @param session
	 * @return
	 */
	@RequestMapping(value="xgpassword")
	public String change(String password,HttpSession session,ModelMap map) {
		Student student = (Student) session.getAttribute("students");
		studentservice.updatepassword(password,student.getId());
		map.put("password", "学生");
		session.removeAttribute("students");
		return "homepage/index";
	}
	
	/***
	 * 显示全班的成绩
	 */
	@RequestMapping(value="showall")
	public String showall(HttpSession session,ModelMap map) {
		Student student = (Student) session.getAttribute("students");
		List<Student> sts=studentservice.findByBjId(student.getBj().getId());
		map.put("sts", sts);
		return "student/showall";
	}
}

